<template>
  <div
    :class="[
      specialBaby ? 'babyInput-special-container' : 'babyInput-container',
      {active: check === 1}
    ]"
    :style="`margin-right:${marginRight}`"
  >
    <span
      v-if="check === 1 && !noCheck"
      class="icon-checkbox-checked"
      @click="$emit('update:check', check === 1 ? 2 : 1)"
    ></span>
    <template v-else>
      <span
        v-if="label !== '持续'"
        class="icon-checkbox-normal"
        @click="$emit('update:check', check === 1 ? 2 : 1)"
      ></span>
    </template>
    <span
      :style="{width: widthspecial, marginRight: `${margin}px`}"
      class="cxk-span"
      @click="$emit('update:check', check === 1 ? 2 : 1)"
      >{{ specialBaby ? label : label.split(':')[0] }}
      <template v-if="!specialBaby">
        <span
          v-if="label.split(':').length === 2"
          style="float: right; margin-right: 2px;"
          >: {{ label.split(':')[1] }}</span
        >
        <span v-if="symptom_id === 13" style="float: right; margin-right: 2px;"
          >: {{ label.split(':')[1] }}</span
        >
      </template>
    </span>

    <el-input
      v-if="symptom_id !== 13"
      v-model="origin"
      class="baby-input"
      @click.native="$emit('update:check', 1)"
    ></el-input>
    <span
      style="margin-left:2px;cursor:pointer"
      class="cxk-unit"
      @click="$emit('update:check', check === 1 ? 2 : 1)"
      >{{ unit }}</span
    >
  </div>
</template>
<script>
export default {
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    label: [String],
    unit: {
      type: String,
      required: false
    },
    check: {},
    value: [String],
    marginRight: {
      type: Number,
      default: 50,
      required: false
    },
    noCheck: [Boolean],
    width: {},
    margin: {},
    symptom_id: {},
    special: {}
  },
  data() {
    return {
      origin: ''
    };
  },
  computed: {
    widthspecial() {
      if (this.symptom_id === 13) {
        return '190px';
      }
      return this.label === '持续' ? 'auto' : '128px';
    },
    specialBaby() {
      return (
        this.label.length > 10 && this.special === 0 && this.symptom_id !== 165
      );
    }
  },
  watch: {
    value(v) {
      this.origin = v;
    },
    origin(v) {
      this.$emit('change', v);
    },
    check(v) {
      if (v === 2) {
        this.origin = '';
      }
    }
  },
  methods: {
    // focus() {
    //   this.focusActive = true;
    // },
    // blur() {
    //   this.focusActive = false;
    // }
  }
};
</script>
<style lang="scss">
.babyInput-container {
  display: flex;
  align-items: center;
  margin-right: 30px;
  flex: 1;
  font-size: 16px;
  .baby-input {
    width: 35px;
    .el-input__inner {
      height: 20px;
      line-height: 20px;
      padding: 0 0px;
      text-align: center;
      border: 1px solid #b3aeae;
    }
  }
  span {
    color: #333;
  }
}
.babyInput-special-container {
  text-align: right;
  padding-right: 10px;
  box-sizing: border-box;
  position: relative;
  .baby-input {
    width: 35px;
    .el-input__inner {
      height: 20px;
      line-height: 20px;
      padding: 0 0px;
      text-align: center;
      border: 1px solid #b3aeae;
    }
  }
  span {
    color: #333;
    line-height: 25px;
    vertical-align: middle;
  }
}
.icon-checkbox-normal {
  width: 12px;
  height: 12px;
  border: 1px solid #b3aeae;
  display: inline-block;
  border-radius: 2px;
  margin-right: 2px;
}
</style>
<style lang="scss">
.babyInput-special-container,
.babyInput-container {
  &.active {
    .el-input.is-active .el-input__inner,
    .el-input__inner:focus {
      background-color: #ffb03e;
      color: #fff;
      border: none;
    }
    .el-input__inner {
      background-color: #ffb03e;
      color: #fff;
      border: none;
    }
    span {
      color: #fff;
    }
    .icon-checkbox-checked {
      color: #ffb03e;
      background-color: #fff;
      border-radius: 2px;
    }
    &.focusActive {
      .el-input__inner {
        background-color: #ffb03e;
        color: #fff;
        border: none;
      }
      span {
        color: #ffb03e;
      }
    }
  }
}
</style>
